<?php
/**
 * Created by JetBrains PhpStorm.
 * User: xx
 * Date: 14-7-24
 * Time: 下午3:44
 * To change this template use File | Settings | File Templates.
 * 目录模型
 */

class menu_model extends CI_Model
{
    function __construct()
    {
        parent::__construct();

        /**
         * 对模块的返回值进行扩展
         * 3000-4000 目录模型使用
         */
        $this->return_status[3001] = "";
        $this->return_status[3002] = "";
    }

    public function get_menu_data()
    {
        $ret = new Ret($this);
        $rows = $this->get_all_data();
        if ($rows) {
            print_r($rows);
        }
        return $ret;
    }

    /**
     * $row = $query->row_array();
     * @return bool
     */
    private function get_all_data()
    {
        $rows = FALSE;
        $sql = "SELECT * FROM " . XS_MENU;
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $rows = $query->result_array();
        }

        return $rows;
    }

    private function add_menu( $data)
    {
        $this->db->insert(XS_MENU, $data);
    }

    private function edit_menu($menu_id, $data)
    {
        $this->db->where('menu_id', $menu_id);
        $this->db->update(XS_MENU, $data);
    }
}